﻿using ReflectionStudio.Core.Events;
using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using WPFExcelReport.Helpers;
using System.Windows.Controls;
namespace WPFExcelReport
{
    /// <summary>
    /// Interaction logic for ProductionOrder.xaml
    /// </summary>
    public partial class UIEKK : ViewBase
    {

        public UIEKK()
        {

        }

        
        public override void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            base.Window_Loaded(sender, e);
            if (IsLoaded)
                return;
            FTAUTOSUM = true;
            TCOUNT1 = "行数";
            TKEY1 = "数量";
            SKEY1 = "EKPSA";
            KEY1 = "EKPME1";
            TKEY2 = "本币";
            SKEY2 = "EKPSA";
            KEY2 = "EKPWE1";
            TKEY3 = "交易";
            SKEY3 = "EKPSA";
            KEY3 = "BUVALUE";
        }


        public override void OnAppModeChg()
        {
            base.OnAppModeChg();
            KRS = MV.year.Substring(2, 2);
            switch (app.company)
            {
                case "TST":
                    switch (app.AppMode)
                    {
                        case "TISSUE":
                            BUKRS = "TSE";
                            //KRS = MV.year.Substring(3, 1) + "S";
                            break;
                        case "TMODE":
                            BUKRS = "TME";
                            //KRS = MV.year.Substring(3, 1) + "M";
                            break;

                    }
                    break;
            }
        }

        public override void ManageCommand(object sender, RoutedEventArgs e)
        {
            VICC_WFEVENTS.SVWF.EK02(RUNID, "B" + KEY);
        }

        public override void LOADBYAUF()
        {
            TBMain.Clear();
            if (ORDERNUM.Length < 9)
                return;
            dwData = TBMain.NewRow();
            dwData["EKKMANDANT"] = app.Mandant;
            dwData["EKKAUFKRS"] = ORDERNUM.Substring(1, 2);
            dwData["EKKAUFLFD"] = ORDERNUM.Substring(3, 6);
            SResult = TMV.QueryEKKOPF(dwData, 3);
            MergeData(SResult, true);
            base.LOADBYAUF();
        }

        public override void SetUpUserRight()
        {
            base.SetUpUserRight();
            IsChgLS = true;
        }

        public void VRManagement(object sender, RoutedEventArgs e)
        {
            VICC_WFEVENTS.SVWF.EKVR02(RUNID, AUF);
        }

        public void EKWB(object sender, RoutedEventArgs e)
        {
            VICC_WFEVENTS.SVWF.EKWB(RUNID, KEY, LO, LB, LP);
        }

        public void KURS_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if (!IsEdit)
                return;

            if (e.Key != System.Windows.Input.Key.Enter)
                return;
            if (e.Key != System.Windows.Input.Key.Return)
                return;
            this.Focus();
            TextBox tb = sender as TextBox;
            tb.Focus();
        }
        public override void InactiveCommand(object sender, RoutedEventArgs e)
        {
            if (dwMaster == null)
                return; 
            dwData = TMV.VEKP.TBMain.NewRow();
            dwData["EKPMANDANT"] = app.Mandant;
            dwData["EKPSA"] = "IN";
            dwData["EKPAUFKRS"] = dwMaster["EKKAUFKRS"];
            dwData["EKPAUFLFD"] = dwMaster["EKKAUFLFD"];
            TMV.VEKP.UpdateEKPOS(dwData, 20);

            dwData = TMV.VZB.TBMain.NewRow();
            dwData["VKZMANDANT"] = app.Mandant;
            dwData["VKZSA"] = "EK";
            dwData["VKZAUFKRS"] = dwMaster["EKKAUFKRS"];
            dwData["VKZAUFLFD"] = dwMaster["EKKAUFLFD"];
            TMV.VZB.UpdateVKZUAB(dwData, app.company, 20);// 无任何该动

            dwData = TMV.MUX.TBMain.NewRow();
            dwData["ABAMANDANT"] = app.Mandant;
            dwData["ABAAUFTYP"] = "B";
            dwData["ABAAUFKRS"] = dwMaster["EKKAUFKRS"];
            dwData["ABAAUFLFD"] = dwMaster["EKKAUFLFD"];
            TMV.MUX.DeleteABAUFM(dwData, 21);

            dwData = TMV.VKD.TBMain.NewRow();
            dwData["VKAMANDANT"] = app.Mandant;
            dwData["VKAAUFKRS"] = dwMaster["EKKAUFKRS"];
            dwData["VKAAUFLFD"] = dwMaster["EKKAUFLFD"];
            dwData["VKASA"] = "EK";
            TMV.VKD.DeleteVKADR(dwData, 20);

            dwData = TMV.VWD.TBMain.NewRow();
            dwData["WDMANDANT"] = app.Mandant;
            dwData["WDAUFKRS"] = dwMaster["EKKAUFKRS"];
            dwData["WDAUFLFD"] = dwMaster["EKKAUFLFD"];
            dwData["WDSA"] = "B";
            TMV.VWD.DeleteWDECK(dwData, 20);
            PM["KRS"] = dwMaster["EKKAUFKRS"].ToString();
            PM["LFD"] = dwMaster["EKKAUFLFD"].ToString();
            TMV.EKPCHG(PM);
            string key = AUF;
            AUF = "";
            AUF = key;
            base.InactiveCommand(sender, e);
        }

    }
    public partial class UIEKK : ViewBase
    {
        public VEKKOPF TMV
        {
            get
            {
                return (VEKKOPF)MV;
            }
        }

        #region ==LIEFNRBY===========
        public static readonly DependencyProperty LIEFNRBYProperty = DependencyProperty.Register("LIEFNRBY",
        typeof(string), typeof(UIEKK),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnLIEFNRBYChanged));
        public string LIEFNRBY
        {
            get
            {
                return (string)GetValue(LIEFNRBYProperty);
            }
            set
            {
                SetValue(LIEFNRBYProperty, value);
                OnLIEFNRBYChg(value);
            }
        }
        private static void OnLIEFNRBYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIEKK;
            if (src != null)
            {
                src.LIEFNRBY = (string)e.NewValue;
            }
        }
        #endregion

        #region ==KURS===========
        public static readonly DependencyProperty KURSProperty = DependencyProperty.Register("KURS",
        typeof(string), typeof(UIEKK),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnKURSChanged));
        public string KURS
        {
            get
            {
                return (string)GetValue(KURSProperty);
            }
            set
            {
                SetValue(KURSProperty, value);
                OnKURSChg(value);
            }
        }
        private static void OnKURSChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIEKK;
            if (src != null)
            {
                src.KURS = (string)e.NewValue;
            }
        }
        public virtual void OnKURSChg(string value)
        {
        }
        #endregion

        #region ==RENR===========
        public static readonly DependencyProperty RENRProperty = DependencyProperty.Register("RENR",
        typeof(string), typeof(UIEKK),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnRENRChanged));
        public string RENR
        {
            get
            {
                return (string)GetValue(RENRProperty);
            }
            set
            {
                SetValue(RENRProperty, value);
            }
        }
        private static void OnRENRChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIEKK;
            if (src != null)
            {
                src.RENR = (string)e.NewValue;
            }
        }
        #endregion

        #region ==AUF===========
        public static readonly DependencyProperty AUFProperty = DependencyProperty.Register("AUF",
        typeof(string), typeof(UIEKK),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnAUFChanged));
        public string AUF
        {
            get
            {
                return (string)GetValue(AUFProperty);
            }
            set
            {
                SetValue(AUFProperty, value);
            }
        }
        private static void OnAUFChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIEKK;
            if (src != null)
            {
                src.AUF = (string)e.NewValue;
            }
        }
        #endregion

        #region ==IsChgZA===========
        public static readonly DependencyProperty IsChgZAProperty = DependencyProperty.Register("IsChgZA",
        typeof(bool), typeof(UIEKK),
        new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsChgZAChanged));
        public bool IsChgZA
        {
            get
            {
                return (bool)GetValue(IsChgZAProperty);
            }
            set
            {
                SetValue(IsChgZAProperty, value);
            }
        }
        private static void OnIsChgZAChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIEKK;
            if (src != null)
            {
                src.IsChgZA = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==IsChgLS===========
        public static readonly DependencyProperty IsChgLSProperty = DependencyProperty.Register("IsChgLS",
        typeof(bool), typeof(UIEKK),
        new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsChgLSChanged));
        public bool IsChgLS
        {
            get
            {
                return (bool)GetValue(IsChgLSProperty);
            }
            set
            {
                SetValue(IsChgLSProperty, value);
            }
        }
        private static void OnIsChgLSChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIEKK;
            if (src != null)
            {
                src.IsChgLS = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==SACHB===========
        public static readonly DependencyProperty SACHBProperty = DependencyProperty.Register("SACHB",
        typeof(string), typeof(UIEKK),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnSACHBChanged));
        public string SACHB
        {
            get
            {
                return (string)GetValue(SACHBProperty);
            }
            set
            {
                SetValue(SACHBProperty, value);
                OnSACHBChg(value);
            }
        }
        private static void OnSACHBChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIEKK;
            if (src != null)
            {
                src.SACHB = (string)e.NewValue;
            }
        }
        public virtual void OnSACHBChg(string value)
        {
            if (IsEdit)
                return;
            if (dwMaster == null)
                return;
            TMV.EKKSACHB = value;
        }

        #endregion

        #region ==LIEFNR===========
        public static readonly DependencyProperty LIEFNRProperty = DependencyProperty.Register("LIEFNR",
        typeof(string), typeof(UIEKK),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnLIEFNRChanged));
        public string LIEFNR
        {
            get
            {
                return (string)GetValue(LIEFNRProperty);
            }
            set
            {
                SetValue(LIEFNRProperty, value);
            }
        }
        private static void OnLIEFNRChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIEKK;
            if (src != null)
            {
                src.LIEFNR = (string)e.NewValue;
            }
        }
        public virtual void OnLIEFNRBYChg(string value)
        {
        }

        #endregion

        #region ==EKAUF===========
        public static readonly DependencyProperty EKAUFProperty = DependencyProperty.Register("EKAUF",
        typeof(string), typeof(UIEKK),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnEKAUFChanged));
        public string EKAUF
        {
            get
            {
                return (string)GetValue(EKAUFProperty);
            }
            set
            {
                SetValue(EKAUFProperty, value);
            }
        }
        private static void OnEKAUFChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIEKK;
            if (src != null)
            {
                src.EKAUF = (string)e.NewValue;
            }
        }
        #endregion

        #region ==LSKOND===========
        public static readonly DependencyProperty LSKONDProperty = DependencyProperty.Register("LSKOND",
        typeof(string), typeof(UIEKK),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnLSKONDChanged));
        public string LSKOND
        {
            get
            {
                return (string)GetValue(LSKONDProperty);
            }
            set
            {
                SetValue(LSKONDProperty, value);
            }
        }
        private static void OnLSKONDChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIEKK;
            if (src != null)
            {
                src.LSKOND = (string)e.NewValue;
            }
        }
        #endregion

        #region ==dwEKK===========
        public static readonly DependencyProperty dwEKKProperty = DependencyProperty.Register("dwEKK",
        typeof(DataRow), typeof(UIEKK),
        new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OndwEKKChanged));
        public DataRow dwEKK
        {
            get
            {
                return (DataRow)GetValue(dwEKKProperty);
            }
            set
            {
                SetValue(dwEKKProperty, value);
            }
        }
        private static void OndwEKKChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIEKK;
            if (src != null)
            {
                src.dwEKK = (DataRow)e.NewValue;
            }
        }
        #endregion

        #region ==KONDSL===========
        public static readonly DependencyProperty KONDSLProperty = DependencyProperty.Register("KONDSL",
        typeof(string), typeof(UIEKK),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnKONDSLChanged));
        public string KONDSL
        {
            get
            {
                return (string)GetValue(KONDSLProperty);
            }
            set
            {
                SetValue(KONDSLProperty, value);
                OnKONDSLChg(value);
            }
        }
        private static void OnKONDSLChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIEKK;
            if (src != null)
            {
                src.KONDSL = (string)e.NewValue;
            }
        }

        public virtual void OnKONDSLChg(string value)
        {

        }

        #endregion

        #region ==IsAUFConirmed===========
        public static readonly DependencyProperty IsAUFConirmedProperty = DependencyProperty.Register("IsAUFConirmed",
        typeof(bool), typeof(UIEKK),
        new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsAUFConirmedChanged));
        public bool IsAUFConirmed
        {
            get
            {
                return (bool)GetValue(IsAUFConirmedProperty);
            }
            set
            {
                SetValue(IsAUFConirmedProperty, value);
                OnIsAUFConirmedChg(value);
            }
        }
        private static void OnIsAUFConirmedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIEKK;
            if (src != null)
            {
                src.IsAUFConirmed = (bool)e.NewValue;
            }
        }
        public void OnIsAUFConirmedChg(bool value)
        {
        }


        #endregion

        #region ==WAEHRSL===========
        public static readonly DependencyProperty WAEHRSLProperty = DependencyProperty.Register("WAEHRSL",
        typeof(string), typeof(UIEKK),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnWAEHRSLChanged));
        public string WAEHRSL
        {
            get
            {
                return (string)GetValue(WAEHRSLProperty);
            }
            set
            {
                SetValue(WAEHRSLProperty, value);
                OnWAEHRSLChg(value);
            }
        }
        private static void OnWAEHRSLChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIEKK;
            if (src != null)
            {
                src.WAEHRSL = (string)e.NewValue;
            }
        }

        public virtual void OnWAEHRSLChg(string value)
        {
            if (!IsEdit)
                return;
            if (dwMaster == null)
                return;
            TMV.EKKWAEHRSL = value;
        }


        #endregion

        #region ==ZAHLBED===========
        public static readonly DependencyProperty ZAHLBEDProperty = DependencyProperty.Register("ZAHLBED",
        typeof(string), typeof(UIEKK),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnZAHLBEDChanged));
        public string ZAHLBED
        {
            get
            {
                return (string)GetValue(ZAHLBEDProperty);
            }
            set
            {
                SetValue(ZAHLBEDProperty, value);
                OnZAHLBEDChg(value);
            }
        }
        private static void OnZAHLBEDChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIEKK;
            if (src != null)
            {
                src.ZAHLBED = (string)e.NewValue;
            }
        }
        public virtual void OnZAHLBEDChg(string lb)
        { }
        #endregion

        #region ==BUKRS===========
        public static readonly DependencyProperty BUKRSProperty = DependencyProperty.Register("BUKRS",
        typeof(string), typeof(UIEKK),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnBUKRSChanged));
        public string BUKRS
        {
            get
            {
                return (string)GetValue(BUKRSProperty);
            }
            set
            {
                SetValue(BUKRSProperty, value);
                if (MV == null) return;
                TMV.EKKBUCHKRS = value;
            }
        }
        private static void OnBUKRSChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIEKK;
            if (src != null)
            {
                src.BUKRS = (string)e.NewValue;
            }
        }
        #endregion

        #region ==VKAUF===========
        public static readonly DependencyProperty VKAUFProperty = DependencyProperty.Register("VKAUF",
        typeof(string), typeof(UIEKK),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnVKAUFChanged));
        public string VKAUF
        {
            get
            {
                return (string)GetValue(VKAUFProperty);
            }
            set
            {
                SetValue(VKAUFProperty, value);
                OnVKAUFChg(value);
            }
        }
        private static void OnVKAUFChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIEKK;
            if (src != null)
            {
                src.VKAUF = (string)e.NewValue;
            }
        }
        public virtual void OnVKAUFChg(string value)
        {
            if (ORDERNUM.Length < 8) return;
            VKKRS = ORDERNUM.Substring(0, 2);
            VKLFD = ORDERNUM.Substring(2, 6);
        }

        #endregion

        #region ==VKKRS===========
        public static readonly DependencyProperty VKKRSProperty = DependencyProperty.Register("VKKRS",
        typeof(string), typeof(UIEKK),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnVKKRSChanged));
        public string VKKRS
        {
            get
            {
                return (string)GetValue(VKKRSProperty);
            }
            set
            {
                SetValue(VKKRSProperty, value);
            }
        }
        private static void OnVKKRSChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIEKK;
            if (src != null)
            {
                src.VKKRS = (string)e.NewValue;
            }
        }
        #endregion

        #region ==VKLFD===========
        public static readonly DependencyProperty VKLFDProperty = DependencyProperty.Register("VKLFD",
        typeof(string), typeof(UIEKK),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnVKLFDChanged));
        public string VKLFD
        {
            get
            {
                return (string)GetValue(VKLFDProperty);
            }
            set
            {
                SetValue(VKLFDProperty, value);
            }
        }
        private static void OnVKLFDChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIEKK;
            if (src != null)
            {
                src.VKLFD = (string)e.NewValue;
            }
        }
        #endregion

        #region ==SART===========
        public static readonly DependencyProperty SARTProperty = DependencyProperty.Register("SART",
        typeof(string), typeof(UIEKK),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnSARTChanged));
        public string SART
        {
            get
            {
                return (string)GetValue(SARTProperty);
            }
            set
            {
                SetValue(SARTProperty, value);
                OnSARTChg(value);
            }
        }
        private static void OnSARTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIEKK;
            if (src != null)
            {
                src.SART = (string)e.NewValue;
            }
        }
        public virtual void OnSARTChg(string sa)
        { }
        #endregion

        #region ==VSPED===========
        public static readonly DependencyProperty VSPEDProperty = DependencyProperty.Register("VSPED",
        typeof(string), typeof(UIEKK),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnVSPEDChanged));
        public string VSPED
        {
            get
            {
                return (string)GetValue(VSPEDProperty);
            }
            set
            {
                SetValue(VSPEDProperty, value);
                OnVSPEDChg(value);
            }
        }
        private static void OnVSPEDChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIEKK;
            if (src != null)
            {
                src.VSPED = (string)e.NewValue;
            }
        }
        public virtual void OnVSPEDChg(string vs)
        { }
        #endregion

        #region ==LIEFBED===========
        public static readonly DependencyProperty LIEFBEDProperty = DependencyProperty.Register("LIEFBED",
        typeof(string), typeof(UIEKK),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnLIEFBEDChanged));
        public string LIEFBED
        {
            get
            {
                return (string)GetValue(LIEFBEDProperty);
            }
            set
            {
                SetValue(LIEFBEDProperty, value);
                OnLIEFBEDChg(value);

            }
        }
        private static void OnLIEFBEDChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIEKK;
            if (src != null)
            {
                src.LIEFBED = (string)e.NewValue;
            }
        }
        public virtual void OnLIEFBEDChg(string lb)
        { }
        #endregion


        #region ==AUFART===========
        public static readonly DependencyProperty AUFARTProperty = DependencyProperty.Register("AUFART",
        typeof(string), typeof(UIEKK),
        new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnAUFARTChanged));
        public string AUFART
        {
            get
            {
                return (string)GetValue(AUFARTProperty);
            }
            set
            {
                SetValue(AUFARTProperty, value);
            }
        }
        private static void OnAUFARTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIEKK;
            if (src != null)
            {
                src.AUFART = (string)e.NewValue;
            }
        }
        #endregion
    }
}
